﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace UdrinkWater_Project.Officer
{
    public partial class TimeList_Emp : System.Web.UI.Page
    {
        string Connection = ConfigurationManager.ConnectionStrings["DB_Udrink"].ConnectionString;
        DataTable dt = new DataTable();
        DataTable OT = new DataTable();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                dt = GetData_TimeNow();
                GV_ShowTime.DataSource = dt;
                GV_ShowTime.DataBind();
                lb_MonthYear.Text = CB_MonthTimeEmp.Text +"  "+ CB_YearTimeEmp.Text;
                DataTable Absence = new DataTable();
                Absence = GetData_Absence();
                lb_jobAbsence.Text = Absence.Rows.Count.ToString();

                OT = GetData_OT();
                GV_ShoeTimeOver.DataSource = OT;
                GV_ShoeTimeOver.DataBind();
            }

        }
        public DataTable GetData_TimeSelect31(string Month,string Year)
        {
            DataTable dt = new DataTable();
            string sqltext = @"SELECT TB_Employee.ID_Card,TB_EmpCheckIn.CheckIn_Date,TB_EmpCheckIn.CheckIn_Time,TB_EmpCheckOut.CheckOut_time,
                               TB_StatusCheckTime.Status_Time FROM TB_EmpCheckIn
                               INNER JOIN TB_EmpCheckOut ON TB_EmpCheckIn.Emp_Date = TB_EmpCheckOut.Emp_Date
                               INNER JOIN TB_Employee ON TB_Employee.ID_Card=TB_EmpCheckIn.Employee_ID
                               LEFT OUTER JOIN TB_StatusCheckTime ON TB_EmpCheckIn.Status_Check = TB_StatusCheckTime.Status_Time_Int
                               WHERE TB_Employee.ID_Card='"+Session["User"].ToString()+"' AND (TB_EmpCheckIn.CheckIn_Date BETWEEN '" + Year + "-" + Month + "-01' AND '" + Year + "-" + Month + "-31')";
            SqlConnection sqlconn = new SqlConnection(Connection);
            SqlDataAdapter da = new SqlDataAdapter(sqltext, sqlconn);
            DataSet ds = new DataSet();
            da.Fill(ds);

            return ds.Tables[0];
        }
        public DataTable GetData_TimeSelect31Ab(string Month, string Year)
        {
            DataTable dt = new DataTable();
            string sqltext = @"SELECT TB_Employee.ID_Card,TB_EmpCheckIn.CheckIn_Date,TB_EmpCheckIn.CheckIn_Time,TB_EmpCheckOut.CheckOut_time,
                               TB_StatusCheckTime.Status_Time FROM TB_EmpCheckIn
                               INNER JOIN TB_EmpCheckOut ON TB_EmpCheckIn.Emp_Date = TB_EmpCheckOut.Emp_Date
                               INNER JOIN TB_Employee ON TB_Employee.ID_Card=TB_EmpCheckIn.Employee_ID
                               LEFT OUTER JOIN TB_StatusCheckTime ON TB_EmpCheckIn.Status_Check = TB_StatusCheckTime.Status_Time_Int
                               WHERE TB_Employee.ID_Card='" + Session["User"].ToString() + "' AND (TB_EmpCheckIn.CheckIn_Date BETWEEN '" + Year + "-" + Month + "-01' AND '" + Year + "-" + Month + "-31') AND TB_EmpCheckIn.Status_Check=2";
            SqlConnection sqlconn = new SqlConnection(Connection);
            SqlDataAdapter da = new SqlDataAdapter(sqltext, sqlconn);
            DataSet ds = new DataSet();
            da.Fill(ds);

            return ds.Tables[0];
        }
       
        public DataTable GetData_TimeSelect30(string Month, string Year)
        {
            DataTable dt = new DataTable();
            string sqltext = @"SELECT TB_Employee.ID_Card,TB_EmpCheckIn.CheckIn_Date,TB_EmpCheckIn.CheckIn_Time,TB_EmpCheckOut.CheckOut_time,
                               TB_StatusCheckTime.Status_Time FROM TB_EmpCheckIn
                               INNER JOIN TB_EmpCheckOut ON TB_EmpCheckIn.Emp_Date = TB_EmpCheckOut.Emp_Date
                               INNER JOIN TB_Employee ON TB_Employee.ID_Card=TB_EmpCheckIn.Employee_ID
                               LEFT OUTER JOIN TB_StatusCheckTime ON TB_EmpCheckIn.Status_Check = TB_StatusCheckTime.Status_Time_Int
                               WHERE TB_Employee.ID_Card='" + Session["User"].ToString() + "' AND (TB_EmpCheckIn.CheckIn_Date BETWEEN '" + Year + "-" + Month + "-01' AND '" + Year + "-" + Month + "-30')";
            SqlConnection sqlconn = new SqlConnection(Connection);
            SqlDataAdapter da = new SqlDataAdapter(sqltext, sqlconn);
            DataSet ds = new DataSet();
            da.Fill(ds);

            return ds.Tables[0];
        }
        public DataTable GetData_TimeSelect30Ab(string Month, string Year)
        {
            DataTable dt = new DataTable();
            string sqltext = @"SELECT TB_Employee.ID_Card,TB_EmpCheckIn.CheckIn_Date,TB_EmpCheckIn.CheckIn_Time,TB_EmpCheckOut.CheckOut_time,
                               TB_StatusCheckTime.Status_Time FROM TB_EmpCheckIn
                               INNER JOIN TB_EmpCheckOut ON TB_EmpCheckIn.Emp_Date = TB_EmpCheckOut.Emp_Date
                               INNER JOIN TB_Employee ON TB_Employee.ID_Card=TB_EmpCheckIn.Employee_ID
                               LEFT OUTER JOIN TB_StatusCheckTime ON TB_EmpCheckIn.Status_Check = TB_StatusCheckTime.Status_Time_Int
                               WHERE TB_Employee.ID_Card='" + Session["User"].ToString() + "' AND (TB_EmpCheckIn.CheckIn_Date BETWEEN '" + Year + "-" + Month + "-01' AND '" + Year + "-" + Month + "-30') AND TB_EmpCheckIn.Status_Check=2";
            SqlConnection sqlconn = new SqlConnection(Connection);
            SqlDataAdapter da = new SqlDataAdapter(sqltext, sqlconn);
            DataSet ds = new DataSet();
            da.Fill(ds);

            return ds.Tables[0];
        }
        public DataTable GetData_TimeSelect29(string Month, string Year)
        {
            DataTable dt = new DataTable();
            string sqltext = @"SELECT TB_Employee.ID_Card,TB_EmpCheckIn.CheckIn_Date,TB_EmpCheckIn.CheckIn_Time,TB_EmpCheckOut.CheckOut_time,
                               TB_StatusCheckTime.Status_Time FROM TB_EmpCheckIn
                               INNER JOIN TB_EmpCheckOut ON TB_EmpCheckIn.Emp_Date = TB_EmpCheckOut.Emp_Date
                               INNER JOIN TB_Employee ON TB_Employee.ID_Card=TB_EmpCheckIn.Employee_ID
                               LEFT OUTER JOIN TB_StatusCheckTime ON TB_EmpCheckIn.Status_Check = TB_StatusCheckTime.Status_Time_Int
                               WHERE TB_Employee.ID_Card='" + Session["User"].ToString() + "' AND (TB_EmpCheckIn.CheckIn_Date BETWEEN '" + Year + "-" + Month + "-01' AND '" + Year + "-" + Month + "-29')";
            SqlConnection sqlconn = new SqlConnection(Connection);
            SqlDataAdapter da = new SqlDataAdapter(sqltext, sqlconn);
            DataSet ds = new DataSet();
            da.Fill(ds);

            return ds.Tables[0];
        }
        public DataTable GetData_TimeSelect29Ab(string Month, string Year)
        {
            DataTable dt = new DataTable();
            string sqltext = @"SELECT TB_Employee.ID_Card,TB_EmpCheckIn.CheckIn_Date,TB_EmpCheckIn.CheckIn_Time,TB_EmpCheckOut.CheckOut_time,
                               TB_StatusCheckTime.Status_Time FROM TB_EmpCheckIn
                               INNER JOIN TB_EmpCheckOut ON TB_EmpCheckIn.Emp_Date = TB_EmpCheckOut.Emp_Date
                               INNER JOIN TB_Employee ON TB_Employee.ID_Card=TB_EmpCheckIn.Employee_ID
                               LEFT OUTER JOIN TB_StatusCheckTime ON TB_EmpCheckIn.Status_Check = TB_StatusCheckTime.Status_Time_Int
                               WHERE TB_Employee.ID_Card='" + Session["User"].ToString() + "' AND (TB_EmpCheckIn.CheckIn_Date BETWEEN '" + Year + "-" + Month + "-01' AND '" + Year + "-" + Month + "-29') AND TB_EmpCheckIn.Status_Check=2";
            SqlConnection sqlconn = new SqlConnection(Connection);
            SqlDataAdapter da = new SqlDataAdapter(sqltext, sqlconn);
            DataSet ds = new DataSet();
            da.Fill(ds);

            return ds.Tables[0];
        }
        public DataTable GetData_TimeSelect28(string Month, string Year)
        {
            DataTable dt = new DataTable();
            string sqltext = @"SELECT TB_Employee.ID_Card,TB_EmpCheckIn.CheckIn_Date,TB_EmpCheckIn.CheckIn_Time,TB_EmpCheckOut.CheckOut_time,
                               TB_StatusCheckTime.Status_Time FROM TB_EmpCheckIn
                               INNER JOIN TB_EmpCheckOut ON TB_EmpCheckIn.Emp_Date = TB_EmpCheckOut.Emp_Date
                               INNER JOIN TB_Employee ON TB_Employee.ID_Card=TB_EmpCheckIn.Employee_ID
                               LEFT OUTER JOIN TB_StatusCheckTime ON TB_EmpCheckIn.Status_Check = TB_StatusCheckTime.Status_Time_Int
                               WHERE TB_Employee.ID_Card='" + Session["User"].ToString() + "' AND (TB_EmpCheckIn.CheckIn_Date BETWEEN '" + Year + "-" + Month + "-01' AND '" + Year + "-" + Month + "-28')";
            SqlConnection sqlconn = new SqlConnection(Connection);
            SqlDataAdapter da = new SqlDataAdapter(sqltext, sqlconn);
            DataSet ds = new DataSet();
            da.Fill(ds);

            return ds.Tables[0];
        }
        public DataTable GetData_TimeSelect28Ab(string Month, string Year)
        {
            DataTable dt = new DataTable();
            string sqltext = @"SELECT TB_Employee.ID_Card,TB_EmpCheckIn.CheckIn_Date,TB_EmpCheckIn.CheckIn_Time,TB_EmpCheckOut.CheckOut_time,
                               TB_StatusCheckTime.Status_Time FROM TB_EmpCheckIn
                               INNER JOIN TB_EmpCheckOut ON TB_EmpCheckIn.Emp_Date = TB_EmpCheckOut.Emp_Date
                               INNER JOIN TB_Employee ON TB_Employee.ID_Card=TB_EmpCheckIn.Employee_ID
                               LEFT OUTER JOIN TB_StatusCheckTime ON TB_EmpCheckIn.Status_Check = TB_StatusCheckTime.Status_Time_Int
                               WHERE TB_Employee.ID_Card='" + Session["User"].ToString() + "' AND (TB_EmpCheckIn.CheckIn_Date BETWEEN '" + Year + "-" + Month + "-01' AND '" + Year + "-" + Month + "-28') AND TB_EmpCheckIn.Status_Check=2";
            SqlConnection sqlconn = new SqlConnection(Connection);
            SqlDataAdapter da = new SqlDataAdapter(sqltext, sqlconn);
            DataSet ds = new DataSet();
            da.Fill(ds);

            return ds.Tables[0];
        }
        public DataTable GetData_TimeNow()
        {
            DataTable dt = new DataTable();
            string sqltext = @"SELECT TB_Employee.ID_Card,TB_EmpCheckIn.CheckIn_Date,TB_EmpCheckIn.CheckIn_Time,TB_EmpCheckOut.CheckOut_time,
                               TB_StatusCheckTime.Status_Time FROM TB_EmpCheckIn
                               INNER JOIN TB_EmpCheckOut ON TB_EmpCheckIn.Emp_Date = TB_EmpCheckOut.Emp_Date
                               INNER JOIN TB_Employee ON TB_Employee.ID_Card=TB_EmpCheckIn.Employee_ID
                               LEFT OUTER JOIN TB_StatusCheckTime ON TB_EmpCheckIn.Status_Check = TB_StatusCheckTime.Status_Time_Int
                               WHERE TB_Employee.ID_Card='"+Session["User"].ToString()+"' AND (TB_EmpCheckIn.CheckIn_Date BETWEEN CONVERT(DATE,DATEADD(s,+1,DATEADD(mm, DATEDIFF(m,0,GETDATE())+0,0))) AND CONVERT(DATE,DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE())+1,0))))";
            SqlConnection sqlconn = new SqlConnection(Connection);
            SqlDataAdapter da = new SqlDataAdapter(sqltext, sqlconn);
            DataSet ds = new DataSet();
            da.Fill(ds);

            return ds.Tables[0];
        }
        public DataTable GetData_Absence()
        {
            DataTable dt = new DataTable();
            string sqltext = @"SELECT TB_Employee.ID_Card,TB_EmpCheckIn.CheckIn_Date,TB_EmpCheckIn.CheckIn_Time,TB_EmpCheckOut.CheckOut_time,
                               TB_StatusCheckTime.Status_Time FROM TB_EmpCheckIn
                               INNER JOIN TB_EmpCheckOut ON TB_EmpCheckIn.Emp_Date = TB_EmpCheckOut.Emp_Date
                               INNER JOIN TB_Employee ON TB_Employee.ID_Card=TB_EmpCheckIn.Employee_ID
                               LEFT OUTER JOIN TB_StatusCheckTime ON TB_EmpCheckIn.Status_Check = TB_StatusCheckTime.Status_Time_Int
                               WHERE TB_Employee.ID_Card='"+Session["User"].ToString()+"' AND (TB_EmpCheckIn.CheckIn_Date BETWEEN CONVERT(DATE,DATEADD(s,+1,DATEADD(mm, DATEDIFF(m,0,GETDATE())+0,0))) AND CONVERT(DATE,DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE())+1,0)))) AND TB_EmpCheckIn.Status_Check=2";
            SqlConnection sqlconn = new SqlConnection(Connection);
            SqlDataAdapter da = new SqlDataAdapter(sqltext, sqlconn);
            DataSet ds = new DataSet();
            da.Fill(ds);

            return ds.Tables[0];
        }

        public DataTable GetData_OT()
        {
            DataTable dt = new DataTable();
            string sqltext = @"SELECT TB_Employee.ID_Card,TB_EmployeeOT_IN.CheckIN_Date,TB_EmployeeOT_IN.CheckIn_Time,TB_EmployeeOT_Out.CheckOut_Time
                               FROM TB_Employee INNER JOIN TB_EmployeeOT_IN ON TB_EmployeeOT_IN.Employee_ID=TB_Employee.ID_Card
                               INNER JOIN TB_EmployeeOT_Out ON TB_EmployeeOT_IN.Emp_Date=TB_EmployeeOT_Out.Emp_Date
                               WHERE TB_Employee.ID_Card='"+Session["User"].ToString()+"' AND (TB_EmployeeOT_IN.CheckIN_Date BETWEEN CONVERT(DATE,DATEADD(s,+1,DATEADD(mm, DATEDIFF(m,0,GETDATE())+0,0))) AND CONVERT(DATE,DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE())+1,0))))";
            SqlConnection sqlconn = new SqlConnection(Connection);
            SqlDataAdapter da = new SqlDataAdapter(sqltext, sqlconn);
            DataSet ds = new DataSet();
            da.Fill(ds);

            return ds.Tables[0];
        }
        public DataTable GetData_OT31(string Month, string Year)
        {
            DataTable dt = new DataTable();
            string sqltext = @"SELECT TB_Employee.ID_Card,TB_EmployeeOT_IN.CheckIN_Date,TB_EmployeeOT_IN.CheckIn_Time,TB_EmployeeOT_Out.CheckOut_Time
                               FROM TB_Employee INNER JOIN TB_EmployeeOT_IN ON TB_EmployeeOT_IN.Employee_ID=TB_Employee.ID_Card
                               INNER JOIN TB_EmployeeOT_Out ON TB_EmployeeOT_IN.Emp_Date=TB_EmployeeOT_Out.Emp_Date
                               WHERE TB_Employee.ID_Card='" + Session["User"].ToString() + "' AND (TB_EmployeeOT_IN.CheckIN_Date BETWEEN '" + Year + "-" + Month + "-01' AND '" + Year + "-" + Month + "-31')";
            SqlConnection sqlconn = new SqlConnection(Connection);
            SqlDataAdapter da = new SqlDataAdapter(sqltext, sqlconn);
            DataSet ds = new DataSet();
            da.Fill(ds);

            return ds.Tables[0];
        }
        public DataTable GetData_OT30(string Month, string Year)
        {
            DataTable dt = new DataTable();
            string sqltext = @"SELECT TB_Employee.ID_Card,TB_EmployeeOT_IN.CheckIN_Date,TB_EmployeeOT_IN.CheckIn_Time,TB_EmployeeOT_Out.CheckOut_Time
                               FROM TB_Employee INNER JOIN TB_EmployeeOT_IN ON TB_EmployeeOT_IN.Employee_ID=TB_Employee.ID_Card
                               INNER JOIN TB_EmployeeOT_Out ON TB_EmployeeOT_IN.Emp_Date=TB_EmployeeOT_Out.Emp_Date
                               WHERE TB_Employee.ID_Card='" + Session["User"].ToString() + "' AND (TB_EmployeeOT_IN.CheckIN_Date BETWEEN '" + Year + "-" + Month + "-01' AND '" + Year + "-" + Month + "-30')";
            SqlConnection sqlconn = new SqlConnection(Connection);
            SqlDataAdapter da = new SqlDataAdapter(sqltext, sqlconn);
            DataSet ds = new DataSet();
            da.Fill(ds);

            return ds.Tables[0];
        }
        public DataTable GetData_OT29(string Month, string Year)
        {
            DataTable dt = new DataTable();
            string sqltext = @"SELECT TB_Employee.ID_Card,TB_EmployeeOT_IN.CheckIN_Date,TB_EmployeeOT_IN.CheckIn_Time,TB_EmployeeOT_Out.CheckOut_Time
                               FROM TB_Employee INNER JOIN TB_EmployeeOT_IN ON TB_EmployeeOT_IN.Employee_ID=TB_Employee.ID_Card
                               INNER JOIN TB_EmployeeOT_Out ON TB_EmployeeOT_IN.Emp_Date=TB_EmployeeOT_Out.Emp_Date
                               WHERE TB_Employee.ID_Card='" + Session["User"].ToString() + "' AND (TB_EmployeeOT_IN.CheckIN_Date BETWEEN '" + Year + "-" + Month + "-01' AND '" + Year + "-" + Month + "-29')";
            SqlConnection sqlconn = new SqlConnection(Connection);
            SqlDataAdapter da = new SqlDataAdapter(sqltext, sqlconn);
            DataSet ds = new DataSet();
            da.Fill(ds);

            return ds.Tables[0];
        }
        public DataTable GetData_OT28(string Month, string Year)
        {
            DataTable dt = new DataTable();
            string sqltext = @"SELECT TB_Employee.ID_Card,TB_EmployeeOT_IN.CheckIN_Date,TB_EmployeeOT_IN.CheckIn_Time,TB_EmployeeOT_Out.CheckOut_Time
                               FROM TB_Employee INNER JOIN TB_EmployeeOT_IN ON TB_EmployeeOT_IN.Employee_ID=TB_Employee.ID_Card
                               INNER JOIN TB_EmployeeOT_Out ON TB_EmployeeOT_IN.Emp_Date=TB_EmployeeOT_Out.Emp_Date
                               WHERE TB_Employee.ID_Card='" + Session["User"].ToString() + "' AND (TB_EmployeeOT_IN.CheckIN_Date BETWEEN '" + Year + "-" + Month + "-01' AND '" + Year + "-" + Month + "-28')";
            SqlConnection sqlconn = new SqlConnection(Connection);
            SqlDataAdapter da = new SqlDataAdapter(sqltext, sqlconn);
            DataSet ds = new DataSet();
            da.Fill(ds);

            return ds.Tables[0];
        }

        protected void bt_ShowReportTimeEmp_Click(object sender, EventArgs e)
        {
            CheckTime ChT = new CheckTime();
            DataTable CheckYear = new DataTable();
            CheckYear = ChT.CheckDayOfYear(CB_YearTimeEmp.Value.ToString());
            string Year = CheckYear.Rows[0]["DayCount"].ToString();
            string Month = CB_MonthTimeEmp.Value.ToString();

            if ((Month == "01") || (Month == "03") || (Month == "05") || (Month == "07") || (Month == "08") || (Month == "10") || (Month == "12"))
            {
                dt=GetData_TimeSelect31(Month, (Convert.ToInt32(CB_YearTimeEmp.Value)-543).ToString());
                GV_ShowTime.DataSource = dt;
                GV_ShowTime.DataBind();

                OT = GetData_OT31(Month, (Convert.ToInt32(CB_YearTimeEmp.Value) - 543).ToString());
                GV_ShoeTimeOver.DataSource = OT;
                GV_ShoeTimeOver.DataBind();

                lb_MonthYear.Text = CB_MonthTimeEmp.Text + "  " + CB_YearTimeEmp.Text;
                DataTable Absence = new DataTable();
                Absence = GetData_TimeSelect31Ab(Month, (Convert.ToInt32(CB_YearTimeEmp.Value) - 543).ToString());
                lb_jobAbsence.Text = Absence.Rows.Count.ToString();
                
            }
            else if ((Month == "04") || (Month == "06") || (Month == "09") || (Month == "11"))
            {
                dt = GetData_TimeSelect30(Month, (Convert.ToInt32(CB_YearTimeEmp.Value) - 543).ToString());
                GV_ShowTime.DataSource = dt;
                GV_ShowTime.DataBind();

                OT = GetData_OT30(Month, (Convert.ToInt32(CB_YearTimeEmp.Value) - 543).ToString());
                GV_ShoeTimeOver.DataSource = OT;
                GV_ShoeTimeOver.DataBind();

                lb_MonthYear.Text = CB_MonthTimeEmp.Text + "  " + CB_YearTimeEmp.Text;
                DataTable Absence = new DataTable();
                Absence = GetData_TimeSelect30Ab(Month, (Convert.ToInt32(CB_YearTimeEmp.Value) - 543).ToString());
                lb_jobAbsence.Text = Absence.Rows.Count.ToString();
            }
            else
            {
                if (Year =="365")
                {
                    dt = GetData_TimeSelect28(Month, (Convert.ToInt32(CB_YearTimeEmp.Value) - 543).ToString());
                    GV_ShowTime.DataSource = dt;
                    GV_ShowTime.DataBind();

                    OT = GetData_OT28(Month, (Convert.ToInt32(CB_YearTimeEmp.Value) - 543).ToString());
                    GV_ShoeTimeOver.DataSource = OT;
                    GV_ShoeTimeOver.DataBind();

                    lb_MonthYear.Text = CB_MonthTimeEmp.Text + "  " + CB_YearTimeEmp.Text;
                    DataTable Absence = new DataTable();
                    Absence = GetData_TimeSelect28Ab(Month, (Convert.ToInt32(CB_YearTimeEmp.Value) - 543).ToString());
                    lb_jobAbsence.Text = Absence.Rows.Count.ToString();
                }
                else
                {
                    dt = GetData_TimeSelect29(Month, (Convert.ToInt32(CB_YearTimeEmp.Value) - 543).ToString());
                    GV_ShowTime.DataSource = dt;
                    GV_ShowTime.DataBind();

                    OT = GetData_OT29(Month, (Convert.ToInt32(CB_YearTimeEmp.Value) - 543).ToString());
                    GV_ShoeTimeOver.DataSource = OT;
                    GV_ShoeTimeOver.DataBind();

                    lb_MonthYear.Text = CB_MonthTimeEmp.Text + "  " + CB_YearTimeEmp.Text;
                    DataTable Absence = new DataTable();
                    Absence = GetData_TimeSelect29Ab(Month, (Convert.ToInt32(CB_YearTimeEmp.Value) - 543).ToString());
                    lb_jobAbsence.Text = Absence.Rows.Count.ToString();
                }
            }

        }

        protected void GV_ShoeTimeOver_CustomUnboundColumnData(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewColumnDataEventArgs e)
        {
            if (e.Column.FieldName == "Total")
            {
                string CheckIn = e.GetListSourceFieldValue("CheckIn_Time").ToString();
                string CheckOut = e.GetListSourceFieldValue("CheckOut_Time").ToString();

                TimeSpan Tp = Convert.ToDateTime(CheckOut) - Convert.ToDateTime(CheckIn);
                var Hour = Tp.Hours;
                var Minue = Tp.Minutes;
                int H = Hour*30;

                if ((Minue) >= 20 && (Minue) <= 50)
                {
                    e.Value = H + (30 / 2);
                }
                if (Minue < 20)
                {
                    e.Value = H;
                }
                if (Minue > 50)
                {
                    e.Value = H + 30;
                }
            }
        }
    }
}